<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
        Object.defineProperty():给某个对象扩展具有描述属性的属性,或者给对象添加存取器属性
      */

      const obj = {
        firstName: "zhang",
        lastName: "san",
      };

      Object.defineProperty(obj, "fullName", {
        //getter函数
        get() {
          return obj.firstName + " " + obj.lastName;
        },
        //setter函数
        set(value) {
          // console.log(value);
          const [firstName, lastName] = value.split(" ");
          obj.firstName = firstName;
          obj.lastName = lastName;
        },
      });
    </script>
  </body>
</html>
